import { NgxMonacoEditorConfig } from "ngx-monaco-editor";

const monacoConfig: NgxMonacoEditorConfig = {
  baseUrl: "assets",
  defaultOptions: { scrollBeyondLastLine: false, fontSize: 18 },
  onMonacoLoad: () => {
    monaco.languages.register({ id: "pcode" });
    monaco.languages.setMonarchTokensProvider("pcode", {
      ignoreCase: true,
      tokenizer: {
        root: [
          [/(((int)|(lit)|(jmp)|(jpc))\s*0)|(opr\s*0\s+\d+)/i, "suit.pcode"],
          [/[a-zA-Z]+/, "instruction.pcode"],
          [/(?<=\b)\d+/, "number.pcode"],
          [/#.*/, "comment.pcode"],
        ],
      },
    });
    monaco.editor.defineTheme("pcode-white", {
      base: "vs",
      inherit: false,
      colors: {},
      rules: [
        { token: "instruction.pcode", foreground: "bbaeee", fontStyle: "bold" },
        { token: "suit.pcode", foreground: "bbaeee", fontStyle: "bold" },
        { token: "comment.pcode", foreground: "008800" },
        { token: "number.pcode", foreground: "237893" },
        { token: "unrecognized.pcode", foreground: "ff0000" },
      ],
    });
  },
};
export default monacoConfig;
